import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-06-25
 * Time: 20:51
 */
//https://leetcode.cn/problems/min-stack/
    //最小栈
class MinStack {
    Stack p1;
    Stack p2;

    public MinStack() {
        p1=new Stack();
        p2=new Stack();
    }

    public void push(int val) {
        p1.push(val);
        if(p2.isEmpty()||val<=(int)p2.peek()){
            p2.push(val);
        }
    }

    public void pop() {
        if(p1.peek().equals(p2.peek())){
            p2.pop();
            p1.pop();
        }
        else{
            p1.pop();
        }
    }

    public int top() {
        return (int)p1.peek();
    }

    public int getMin() {
        return (int)p2.peek();
    }
}
public class Test {
    public static void main(String[] args) {
        MinStack minStack=new MinStack();
        minStack.push(new Integer(512));
        minStack.push(new Integer(-1024));
        minStack.push(new Integer(-1024));
        minStack.push(new Integer(512));
        minStack.pop();
        System.out.println(minStack.top());
        minStack.pop();
        System.out.println(minStack.top());
        minStack.pop();
        System.out.println(minStack.top());
    }
}
